package com.cpj.bsyyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpj.bsyyzx.entity.NContent;
import com.cpj.bsyyzx.entity.NurseRecord;
import com.cpj.bsyyzx.entity.StaffManagement;
import com.cpj.bsyyzx.service.IStaffManagementService;
import com.cpj.bsyyzx.util.CommonResult;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 五个臭皮匠
 * @since 2021-04-27
 */
@RestController
@RequestMapping("/staffManagement")
@Log4j
public class StaffManagementController {


    @Autowired
    IStaffManagementService staffManagementService;

    @RequestMapping("/list")
    CommonResult list(Page page, StaffManagement staffManagement){
        QueryWrapper<StaffManagement> queryWrapper = new QueryWrapper<>();
        log.debug("分页查询");
        Page<StaffManagement> rpage=staffManagementService.pageList(page,staffManagement);
        return CommonResult.success(rpage);
    }


    @RequestMapping("save")
    @ResponseBody
    CommonResult save(StaffManagement staffManagement) {
        log.debug("保存");
        boolean success = staffManagementService.saveOrUpdate(staffManagement);
        return CommonResult.success(success);
    }

    @RequestMapping("toedit")
    @ResponseBody
    public CommonResult toedit(ModelMap map, Integer nId) {
        log.debug("跳转到修改页面");
        StaffManagement staffManagement = staffManagementService.getById(nId);
        map.addAttribute("staffManagement", staffManagement);
        return CommonResult.success(staffManagementService.getById(nId));
    }

    @RequestMapping("delete/{id}")
    @ResponseBody
    CommonResult delete(@PathVariable Integer id) {
        log.debug("根据主键删除:" + id);
        boolean success = staffManagementService.removeById(id);
        return CommonResult.success(success);
    }
    @RequestMapping("findHealthHousekeeper")
    @ResponseBody
    CommonResult findHealthHousekeeper(){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("staff_sort","健康管家");
        wrapper.eq("staff_state","在职");
        return CommonResult.success(staffManagementService.list(wrapper));
    }

    @RequestMapping("findDoctor")
    @ResponseBody
    CommonResult findDoctor(){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("staff_sort","医生");
        wrapper.eq("staff_state","在职");
        return CommonResult.success(staffManagementService.list(wrapper));
    }

    @RequestMapping("getPeopleData")
    CommonResult getPeopleData(){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("staff_sort","护工");
        wrapper.eq("staff_state","在职");
        return CommonResult.success(staffManagementService.list(wrapper));
    }
}
